package com.czxy.dao;

import com.czxy.domain.User;
import com.czxy.utils.MyBatisUtils;

import java.util.List;

/**
 * @version v 1.0
 * @Author kami
 * @Date 2019/4/28
 */
public class UserDao {

    //根据username查询user
    public User findUserByUsername(String username){
        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
        User userByUserName = mapper.findUserByUserName(username);
        MyBatisUtils.close();
        return userByUserName;
    }

    public List<User> findAll() {
        UserMapper userMapper = MyBatisUtils.getMapper(UserMapper.class);
        List<User> userList = userMapper.findAll();
        MyBatisUtils.close();
        return userList;
    }

    public boolean insert(User user){
        try {
            UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
            mapper.insert(user);
            MyBatisUtils.commitAndClose();
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
}
